using System.Collections.Generic;
using Belmost4PDA.Constants;
using Belmost4PDA.Fasade;

namespace Belmost4PDA.Logic
{
    public class StatesBuilder
    {
        public StatesReader reader = null;
        /// <summary>
        /// Initializes a new instance of the <see cref="StatesBuilder"/> class.
        /// </summary>
        public StatesBuilder()
        {
            reader = new StatesReader();
        }
        /// <summary>
        /// Creates list of States.
        /// </summary>
        /// <returns></returns>
        public virtual List<StateRecord> Create()
        {
            List<StateData> states = reader.Load();
            List<StateRecord> records = new List<StateRecord>();
            bool isLight = (MainParams.GetParam(MainParams.ParamName.isLight)=="1");
            foreach (StateData data in states)
            {
                StateRecord record;
                switch (data.ID)
                {
                    case ModesIDs.Mode_ChooseBr :
                        record = new StateRecordBr(data.ID, data.Text, data.StartPanel);
                        break;
                    case ModesIDs.Mode_Edit:
                        record = new StateRecordEdit(data.ID, data.Text, data.StartPanel);
                        break;
                    case ModesIDs.Mode_View:
                        record = new StateRecordView(data.ID, data.Text, data.StartPanel);
                        break;
                    case ModesIDs.Mode_EditElemTree:
                        record = new StateRecordElem(data.ID, data.Text, data.StartPanel);
                        break;
                    case ModesIDs.Mode_EditDef:
                        record = new StateRecordDef(data.ID, data.Text, data.StartPanel);
                        break;
                    case ModesIDs.Mode_Exit: //exit ID
                        record = new StateRecord(data.ID, data.Text, data.StartPanel);
                        break;
                    default:
                        record = new StateRecord(ModesIDs.Mode_Exit, data.Text, -1);
                        break;
                }
                if (isLight)
                {
                    if(data.ID!=ModesIDs.Mode_Edit)
                        records.Add(record);
                }
                else
                {
                    if (data.ID != ModesIDs.Mode_View)
                        records.Add(record);
                }
            }
            return records;
        }
    }
}
